﻿using Model;
using Models;
using Newtonsoft.Json.Linq;
using PublicMethod;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace OrderingOnlineWeChat.Controllers
{
    public class ShoppingCartController : BaseControl
    {
        // GET: /ShoppingCart/
        #region 声明
        ZHHQService.Service1Client server1 = new ZHHQService.Service1Client();
        DCXTService.Service1Client server2 = new DCXTService.Service1Client();
        #endregion

        #region 视图
        public ActionResult Index()
        {
            return View();         
        }
        #endregion

        #region 购物车
        /// <summary>
        /// 商品加入购物车
        /// </summary>
        /// <param name="OperID">用户ID</param>
        /// <param name="DisheID">商品ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public ActionResult Order_ShoppingCar_Add(int OperID, string DisheID, string YZM, int RETID)
        {
            try
            {
                View_User userinfoModel = (View_User)Session[SessionStorage.UserLogin];
                if (userinfoModel != null)
                {
                    OperID = userinfoModel.AccID;
                    string result = server2.Order_ShoppingCar_Add(OperID, DisheID, YZM, RETID);
                    return Content(result);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return Content("加入购物车失败，" + ex.Message);
            }
        }

        /// <summary>
        /// 更新商品购物车信息
        /// </summary>
        /// <param name="CarID">购物车ID</param>
        /// <param name="Num">数量</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public ActionResult Order_ShoppingCar_Update(string CarID, int Num, string YZM, int RETID)
        {
            try
            {
                string result = server2.Order_ShoppingCar_Update(CarID, Num, YZM, RETID);
                return Content(result);
            }
            catch (Exception) { return null; }
        }

        /// <summary>
        /// 删除商品购物车信息（可批量删除）
        /// </summary>
        /// <param name="CarID">购物车ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public ActionResult Order_ShoppingCar_Del(string CarID, string YZM, int RETID)
        {
            try
            {
                string result = server2.Order_ShoppingCar_Del(CarID, YZM, RETID);
                return Content(result);
            }
            catch (Exception) { return null; }
        }

        /// <summary>
        /// 获取购物车信息
        /// </summary>
        /// <param name="OperID">用户ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public ActionResult Get_Order_Dishes_ShoppingCar(int OperID, string YZM, int RETID)
        {
            try
            {
                View_User userinfoModel = (View_User)Session[SessionStorage.UserLogin];
                if (userinfoModel != null)
                {
                    OperID = userinfoModel.AccID;
                    string result = server2.Get_Order_Dishes_ShoppingCar(OperID, YZM, RETID);
                    return Content(result);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return Content("获取购物车信息失败，" + ex.Message);
            }
        }
        #endregion

    }
}
